package com.hjq.demo.http.model

/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/AndroidProject-Kotlin
 *    time   : 2019/12/07
 *    desc   : 统一接口数据结构
 */
open class HttpData<T> {

    /** 响应头  */
    private var responseHeaders: Map<String, String>? = null

    /** 返回码 */
    private val errorCode: Int = 0

    /** 提示语 */
    private val errorMsg: String? = null

    /** 数据 */
    private val data: T? = null

    fun setResponseHeaders(responseHeaders: Map<String, String>) {
        this.responseHeaders = responseHeaders
    }

    fun getResponseHeaders(): Map<String, String>? {
        return responseHeaders
    }

    fun getCode(): Int {
        return errorCode
    }

    fun getMessage(): String? {
        return errorMsg
    }

    fun getData(): T? {
        return data
    }

    /**
     * 是否请求成功
     */
    fun isRequestSuccess(): Boolean {
        return errorCode == 200
    }

    /**
     * 是否 Token 失效
     */
    fun isTokenInvalidation(): Boolean {
        return errorCode == 1001
    }
}